﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................
namespace QLKTX1._0.DAO
{
    class KhungGiaNhaDAO
    {
        public static List<KhungGiaNhaDTO> dsKhungGiaNha()
        {
            List<KhungGiaNhaDTO> dsKhungGiaNha = new List<KhungGiaNhaDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM khungGiaNha");

            for(int i=0;i<dt.Rows .Count ;i++)
            {
                KhungGiaNhaDTO khungGiaNha = new KhungGiaNhaDTO();
                khungGiaNha.MaKhungGia = Int32.Parse(dt.Rows [i]["maKhungGia"].ToString ());
                khungGiaNha .TenKhungGia =dt.Rows [i]["tenKhungGia"].ToString ();
                dsKhungGiaNha.Add(khungGiaNha );
            }
            return dsKhungGiaNha;

        }
        //Ham Insert
        public static bool themKhungGianNha(KhungGiaNhaDTO  khungGiaNha)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO khungGiaNha(tenKhungGia) VALUES(N'" + khungGiaNha .TenKhungGia  + "')");
          
        }
        //Ham Delete
        public static bool xoaKhungGianNha(KhungGiaNhaDTO khungGiaNha)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM khungGiaNha WHERE maKhungGia=" + khungGiaNha .MaKhungGia  + "");
        }
        //Ham Update
        public static bool capNhatKhungGianNha(KhungGiaNhaDTO khungGiaNha)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE khungGiaNha set tenKhungGia=N'" + khungGiaNha.TenKhungGia + "' WHERE maKhungGia=" + khungGiaNha.MaKhungGia + "");
        }
    }
}
